package com.gtxc.kotlinmvvm.view;

/**
 * FileName:MyPopupWindow
 * Author：Administrator
 * Date:2021 2021/9/30 15:46
 * Copyright (C), 2020-2021,成都拇音科技有限公司
 * <p>
 * <p>
 * Description: zwl
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */


import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.widget.PopupWindow;

/**
 * Des: 自定义PopupWindow
 * Created by kele on 2020/7/21.
 * E-mail:984127585@qq.com
 */
public class MyPopupWindow extends PopupWindow {

    public MyPopupWindow(View contentView, int width, int height, boolean b) {
        super(contentView, width, height, b);
    }

    @Override
    public void showAsDropDown(View anchor) {
        if (Build.VERSION.SDK_INT >= 24) {
            Rect rect = new Rect();
            anchor.getGlobalVisibleRect(rect);
            int heightPixels = anchor.getResources().getDisplayMetrics().heightPixels;
            int h = heightPixels - rect.bottom;
            //设置负值能达到自适应的效果
            setHeight(-20);
        }
        super.showAsDropDown(anchor);
    }
}